<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>出库管理</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/dateUtil.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
.inputSize {
	width: 150px;
}
select{
	width: 150px;
	font-size: 12px;
}
td{
	font-size: 12px
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		出入库管理 &gt; 库存变更记录
</div>

<form action="../../stockmanage/stockHistoryController/pageFinderStockHistory.do" method="post" >
<div id="searchbar">
<br>
	<table  style="width: 90%" border=0> 
		<tr>
			<td  width="13%">
      		出入库单号：
      		</td>
      		<td width="18%">
      			 <input id="stockNo" name="stockNo" type="text" value="${stockHistory.stockNo}"  class="inputSize"/>
      		</td>
      		<td width="13%">
      			出入库类型：
      		</td>
      		<td id="stockTypeTd">	
      			<select   id="stockType"  name="stockType">
		            <option value="">请选择</option>
		            <option value="1" <c:if test="${stockHistory.stockType=='1'}">selected="selected"</c:if>>货品采购入库</option>
		            <option value="2" <c:if test="${stockHistory.stockType=='2'}">selected="selected"</c:if>>订单退换货入库</option>
<%-- 		            <option value="3" <c:if test="${stockHistory.stockType=='3'}">selected="selected"</c:if>>次品换货入库</option>
 --%>		            <option value="4" <c:if test="${stockHistory.stockType=='4'}">selected="selected"</c:if>>采购退换货入库</option>
		            <option value="5" <c:if test="${stockHistory.stockType=='5'}">selected="selected"</c:if>>调拨入库</option>
		            <option value="6" <c:if test="${stockHistory.stockType=='6'}">selected="selected"</c:if>>其他入库</option>
    	  			<option value="-1" <c:if test="${stockHistory.stockType=='-1'}">selected="selected"</c:if>>包裹销售出库</option>
    	  			<option value="-2" <c:if test="${stockHistory.stockType=='-2'}">selected="selected"</c:if>>采购退换货出库</option>
    	  		    <option value="-3" <c:if test="${stockHistory.stockType=='-3'}">selected="selected"</c:if>>次品退货出库</option>
    	  			<option value="-4" <c:if test="${stockHistory.stockType==-4}">selected="selected"</c:if>>订单退换货出库</option>
    	  		    <option value="-5" <c:if test="${stockHistory.stockType==-5}">selected="selected"</c:if>>调拨出库</option>
    	  		</select>
    		<td>
    		<td colspan="3"></td>
	    </tr>
	    <tr style="height: 9px">
     		<td colspan="8"></td>
    	</tr>
	    <tr>
	    	<td>
	    		采购单号：
			</td>
			<td>
				<input id="purNo" name="purNo" type="text" value="${stockHistory.purNo}"   class="inputSize"/>
	  		</td>
	  		<td>
	  			    商品编号：
	  		</td>
	  		<td>
	 			<input id="commoNo" name="commoNo" type="text" value="${stockHistory.commoNo}"    class="inputSize"/>
			</td>
	  		<td>
	  			    商品名称：
	  		</td>
	  		<td>
	 			<input id="commoName" name="commoName" type="text" value="${stockHistory.commoName}"    class="inputSize"/>
			</td>
			<td colspan="2"></td>
 		</tr>
 		<tr style="height: 9px">
     		<td colspan="8"></td>
    	</tr>
 		<tr>
	     	<td>
	     		仓库：
	     	</td>
	     	<td id = "whTd">
	     	 <select id="whNo"  name="whNo">
	            <option value="">请选择</option>
	            <c:forEach var="temp" items="${whareHouse}">
	            	<option value="${temp.whNo}" <c:if test="${stockHistory.whNo==temp.whNo}">selected="selected"</c:if>>${temp.whName}</option>
	            </c:forEach>
	        </select>
	        </td>
			<td>
	     		出入库时间： 
	     	</td>
	     	<td>	
	     		<input style="width: 150px" id="beginTime" type="text" name="beginTime" readonly="readonly" value="${stockHistory.beginTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}'})" >
			</td>
			<td>
				至
			</td>
			<td>
			<input style="width: 150px" id="endTime" type="text" name="endTime" readonly="readonly" value="${stockHistory.endTime}" class="Wdate" value="" size="21"
	    	onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'beginTime\')||\'2013-01-01\'}'})" >
			</td>
			<td colspan="2">
			   <input id="btnOK" type="submit" value="查询" class="l-button-search" />
	           <input type="button" id="resetBtn" value="重置" class="l-button-search" />
	         <!--   <input type="button" id="importBtn" value="导出" class="l-button-search" /> -->
	  		</td>
  		</tr>
	</table>
</div>
</form>

<div id="dataGrid" style="margin:0; padding:0"></div>
<script>
    var basePath='${BasePath}';
    var toDownloadStockHistory = basePath + '/stockmanage/stockHistoryController/toDownloadStockHistory.do';
    var grid = null;
    var parms = {
    		stockNo : "${stockHistory.stockNo}",
     		stockType : "${stockHistory.stockType}",
     		whNo : "${stockHistory.whNo}",
     		commoName : "${stockHistory.commoName}",
     		purNo : "${stockHistory.purNo}",
     		beginTime : "${stockHistory.beginTime}",
     		commoNo : "${stockHistory.commoNo}",
     		endTime : "${stockHistory.endTime}"
     } 
    
    var importData = function(){
		var m = $.ligerDialog.open({
				title:'导出库存变更记录',
				url: toDownloadStockHistory,
				height:450,
				width:500,
				isResize: false,
				isDrag: false,
				
		});
		m.show(); 
    };
    
    $(function () {
    	 // 重置
        $("#resetBtn").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});
    	 
    	// 导出
        $("#importBtn").click(importData);
        
        grid = $("#dataGrid").ligerGrid({
            columns: [
            { display: '货品编号', name: 'prodNo'},
            { display: '商品编号', name: 'commoNo'},
            { display: '商品名称', name: 'commoName'},
            { display: '货品规格', name: 'specification'},
            { display: '供应商名称', name: 'supName'},
            { display: '仓库', name: 'whName'},
            { display: '出入库时间', name: 'createTime',render: function(rowdata, rowindex, value){
     		   	if(value == '' || value == null){
     				return  "";
     			}
     		   	value = getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
     			return value
     		}},
            { display: '出入库', name: 'stockType',render:function(rowdata,rowindex,value){
            	if(parseInt(value) < 0){
                 	return "出库";
                }else if(parseInt(value) > 0){
                	 return "入库";
                }
            }},
            { display: '出入库单号', name: 'stockNo'},
            { display: '出入库类型', name: 'stockType',render:function(rowdata,rowindex,value){
            	if(parseInt(value) == 1){
                 	return "货品采购入库";
                }else if(parseInt(value) == 2){
                	 return "订单退换货入库";
                }else if(parseInt(value) == 3){
                	 return "次品换货入库";
                }else if(parseInt(value) == 4){
                	 return "采购退换货入库";
                }else if(parseInt(value) == 5){
                	 return "调拨入库";
                }else if(parseInt(value) == 6){
                	 return "其他入库";
                }else if(parseInt(value) == -1){
                	 return "包裹销售出库";
                }else if(parseInt(value) == -2){
                	 return "采购退换货出库";
                }else if(parseInt(value) == -3){
                	 return "次品退货出库";
                }else if(parseInt(value) == -4){
                	 return "订单退换货出库";
                }else if(parseInt(value) == -5){
                	 return "调拨出库";
                }
            	return "";
            }},
            { display: '采购单号', name: 'purNo'},
            { display: '原库存', name: 'originalQuantity'},
            { display: '出入数量', name: 'stockType',render:function(rowdata,rowindex,value){
            	 if(parseInt(value) < 0 && parseInt(rowdata.changeQuantity) > 0){
            		 return '-'+rowdata.changeQuantity;
                 }else if(parseInt(value) > 0){
                	 return '+'+rowdata.changeQuantity;
                 }
                return '0';
            }},
            { display: '出入后库存', name: 'stockType' ,render:function(rowdata,rowindex,value){
            	var total = 0;
            	 if(parseInt(value) < 0 && parseInt(rowdata.changeQuantity) > 0){
             		total = parseInt(rowdata.originalQuantity) - parseInt( rowdata.changeQuantity);
                 }else if(parseInt(value) > 0){
                	total = parseInt(rowdata.originalQuantity) + parseInt( rowdata.changeQuantity);
             		total = total > 0 ? total : 0;
             	}
            	return ''+total; 
            }},
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
				{name: "stockNo", value:$("#stockNo").val()},
				{name: "stockType", value:$("#stockType").val()},
				{name: "whNo", value:$("#whNo").val()},
				{name: "commoName", value:$("#commoName").val()},
				{name: "purNo", value:$("#purNo").val()},
				{name: "beginTime", value : getFullTime($("#beginTime").val(),true)},
				{name: "commoNo", value :$("#commoNo").val()},
				{name: "endTime", value : getFullTime($("#endTime").val(),false)} 
             ],
             url: "ajaxPageFinderStockHistory.do",
             toolbar: {items: [{ text:getDownloadUrl(), click: function(){}, icon: "down" }]}
        });
    });
    function getDownloadUrl(){
 		var parms = "?stockNo="+$("#stockNo").val()
 					+"&stockType="+$("#stockType").val()
					+"&whNo="+ $("#whNo").val()
					+"&commoName="+$("#commoName").val()
					+"&purNo="+$("#purNo").val()
					+"&commoNo="+$("#commoNo").val()
					+"&beginTime="+ getFullTime($("#beginTime").val(),true)
					+"&endTime="+ getFullTime($("#endTime").val(),false)
    	return downloadFile = "<a style = 'color:black' href='${BasePath}/stockmanage/stockHistoryController/downloadStockHistory.do"+parms+"'>导出数据</a>";
    }
</script>
</body>
</html>